<?php
/**
 * Main.php
 *
 * This is an example of the main page of a website. Here
 * users will be able to login. However, like on most sites
 * the login form doesn't just have to be on the main page,
 * but re-appear on subsequent pages, depending on whether
 * the user has logged in or not.
 *
 * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 * Last Updated: August 26, 2004
 */
 
 /**
 * Customized by: Daniel Barnett (Bugs Bee Gone Computer Services)
 * Last Modified: 2007-06-07
 */
 
// Require session.php for user access control
require_once "include/session.php";
// Require config.inc.php for Configuration variables
require_once "include/config.inc.php";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Bugs Bee Gone - Secure Area</title>
    <link href="main.css" type="text/css" rel="stylesheet" />
</head>

<body>

<table>
<tr><td>

<?php
/**
 * User has already logged in, so display relavent links, including
 * a link to the admin center if the user is an administrator.
 */
if($session->logged_in) {
   echo '<img src="../images/logo.jpg" height="64" width="288" alt="Bugs Bee Gone logo" />';
   echo "<h2><u>Logged In</u></h2>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br /><br />"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
       ."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
   }
   echo "[<a href=\"process.php\">Logout</a>]<br />";

   if($session->isAdmin()){
      echo "<br />[<a href=\"contacts.php\">Contacts</a>] &nbsp;&nbsp;[<a href=\"invoices.php\">Invoices</a>]";
      echo " &nbsp;&nbsp;[<a href=\"files.php\">File Manager</a>] &nbsp;&nbsp;[<a href=\"download.php?id=14\">System Auditor</a>]";
   } else {
      echo "<br />[<a href=\"contacts.php\">Contacts</a>] &nbsp;&nbsp;[<a href=\"invoices.php\">Invoices</a>]";
   }
}
else{
?>

<img src="../images/logo.jpg" height="64" width="288" alt="Bugs Bee Gone logo" />
<h2><u>Login</u></h2>
<?php
/**
 * User not logged in, display the login form.
 * If user has already tried to login, but errors were
 * found, display the total number of errors.
 * If errors occurred, they will be displayed.
 */
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time &nbsp;&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
</table>
</form>

<?php
}

/**
 * Just a little page footer, tells how many registered members
 * there are, how many users currently logged in and viewing site,
 * and how many guests viewing site. Active users are displayed,
 * with link to their user information.
 */
if($session->logged_in){
    echo "</td></tr><tr><td align=\"center\"><br><br>";
    echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
    echo "There are $database->num_active_users registered members and ";
    echo "$database->num_active_guests guests viewing the site.<br><br>";

    include("include/view_active.php");
}
?>

</td></tr>
</table>

<?php
    footer();
?>

<br /><p style="font-size:8pt; font-style:italic; font-weight:normal; text-align:left;">Updated 2007-06-11</p>

</body>
</html>
